import {abstractValidator} from "./abstractValidator";
import {mc_validatorResult} from "../model/mc_validatorResult";
import {requireValidator} from "./requireValidator";
/**
 * Created by ybjaa on 2017/6/28.
 */
export class maxLengthValidator extends abstractValidator{

    protected max:number=0;


    public setParameters(max:number=0): void {
        this.max=max;
    }

    protected getValidator(value:string): mc_validatorResult {

        if(typeof(value) != "string"){
            this.setResult(false,"数据类型不对");
            this.result.result=false;
        }

        //判断是否为空
        let validator=new requireValidator();
        this.setValidatorClass(validator);
        let result=validator.validator(value);
        if(!result.result) return result;


        //判断最大长度
        if(value.length>this.max){
            this.setResult(false,"长度大于"+this.max);
        }

        return this.result;
    }
}